﻿using System;
using System.Collections.ObjectModel;
using System.Windows;
using jSLCore.Client.Presentation.BaseControl;
using jSLCore.Client.Presentation.jBinding;

namespace jSLApp.Client.Wpf.Forms
{
    /// <summary>
    /// Interaction logic for TelForm.xaml
    /// </summary>
    public partial class TelForm : DialogControl
    {
        public TelForm()
        {
            InitializeComponent();
        }

        public override bool IsOkVisible
        {
            get { return true; }
        }

        public override bool IsStandartOkCancelEnabled
        {
            get { return true; }
        }

        public override void LoadInitialData()
        {
            GenerateData();


            grid.ItemsSource = ds;
        }

        #region stuff
        private void GenerateData()
        {
            var myData = new MyData();
            myData.Id = 4;
            myData.Name = "Николай";
            myData.Date = DateTime.Now.AddDays(13);
            myData.Money = new decimal(235623.24f);
            myData.Perc = 24;
            myData.Amount = 634;
            DataContext = myData;

            Bind();
        }

        private void MoreThanToday_Rule(object sender, GenericEventArgs2<object, object> e)
        {
            if (((DateTime?)e.Parameter1) <= DateTime.Now)
            {
                throw new jValidationException(jValidationResultType.Warning, "Слишком маленькая дата");
            }
        }

        ObservableCollection<MyData> ds = new ObservableCollection<MyData>();

        private void add_Clicked(object sender, RoutedEventArgs e)
        {
            ds.Add((MyData)DataContext);

            GenerateData();
        } 
        #endregion
    }
    public class MyData
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public DateTime Date { get; set; }
        public decimal Money { get; set; }
        public int Amount { get; set; }
        public float Perc { get; set; }
        public int Simple { get; set; }
    }
}
